package com.msb.test14;

import java.io.*;
import java.net.ServerSocket;
import java.net.Socket;

//服务端
public class TestServer {
    public static void main(String[] args) throws IOException {
        System.out.println("服务端启动");
        //1.套接字确认端口号
        ServerSocket ss=new ServerSocket(8888);
        //2.等待客户端发送数据
        Socket s = ss.accept();
        //3.获取数据流
        InputStream is = s.getInputStream();
        DataInputStream dis=new DataInputStream(is);
        OutputStream os = s.getOutputStream();
        DataOutputStream dos=new DataOutputStream(os);
        //4.接收数据
        String str = dis.readUTF();
        System.out.println("客户端说："+str);
        dos.writeUTF("你好客户端，我接收到您的消息了");
        //5.流、数据网络资源关闭
        dos.close();
        os.close();
        dis.close();
        is.close();
        s.close();
        ss.close();

    }
}
